/*
 * @lc app=leetcode.cn id=695 lang=javascript
 *
 * [695] 岛屿的最大面积
 */

// @lc code=start
/**
 * @param {number[][]} grid
 * @return {number}
 */
var maxAreaOfIsland = function (grid) {
  const rowSize = grid.length
  const colSize = grid[0].length
  let maxLen=0
  const dfs = (target) => {
    const queque = [target]
    let len=0
    while (queque.length) {
      const {row,col} = queque.shift()
      if (row < 0 || col < 0 || row >= rowSize || col >= colSize || grid[row][col] !== 1) {
        continue
      }
      len++
      grid[row][col] = 2
      queque.push({row:row-1,col:col})
      queque.push({row:row,col:col+1})
      queque.push({row:row+1,col:col})
      queque.push({row:row,col:col-1})
    }
    maxLen=Math.max(maxLen, len)
  }
  for (let row = 0; row < rowSize; row++){
    for (let col = 0; col < colSize; col++){
      if (grid[row][col] === 1) {
        dfs({row,col})
      }
    }
  }
return maxLen
};
// @lc code=end

